package com.matrix.im.domain.model;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;

/**
 * @author 有点甜
 * @since 2025/7/30
 */
@Data
@Document(collection = "chat_messages")
public class ChatMessage {
    @Id
    private String id;

    @Indexed
    private String conversationId;

    @Indexed
    private Long fromUserId;

    @Indexed
    private Long toUserId;

    private String content;

    private String messageType;

    @Indexed
    private String status;

    @Indexed
    private Date timestamp;

    private ChatMessage() {}

    public static ChatMessage create(String conversationId, Long fromUserId, Long toUserId, String content, String messageType) {
        ChatMessage message = new ChatMessage();
        message.conversationId = conversationId;
        message.fromUserId = fromUserId;
        message.toUserId = toUserId;
        message.content = content;
        message.messageType = messageType;
        message.timestamp = new Date();
        message.status = "SENT";
        return message;
    }
}
